home *** CD-ROM | disk | FTP | other *** search
/ Computer Inter@ctive 17 / Computer Interactive cdrom 17 - gen 99.iso / ZDNETIT / CONTENT / OPTIVDOS.ZIP / INCLUDE.ZIP / VECLIB.H < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-21  |  6.9 KB  |  197 lines

  1. /*  VecLib.h
  2.  
  3.   vector management functions.
  4.  
  5.   Contains the basic definitions for VectorLib.
  6.  
  7.   Copyright (c) 1996-1998 by Martin Sander
  8.   All Rights Reserved.
  9. */
  10.  
  11. #ifndef __VECLIB_H
  12. #define __VECLIB_H
  13.  
  14. /*    #define V_trapIntError 1   */
  15.            /*  activate this line, if you wish to generate an error
  16.                message and/or terminate program execution in case
  17.                of INTEGER OVERFLOW or INTEGER DOMAIN errors!
  18.                Additionally, you have to make one call to
  19.                V_setIntErrorHandling with either ierrNote or
  20.                ierrAbort as argument.    */
  21.  
  22. #include <stdio.h>
  23. #ifdef __BORLANDC__
  24.        /* the following statements apply to
  25.           VectorLib for Borland C++ */
  26.     #ifdef _Windows
  27.         #define _WINDOWS
  28.         #include <windows.h>
  29.     #else
  30.         #include <alloc.h>
  31.     #endif
  32.     #if defined (V_useHUGE) || defined (__HUGE__)
  33.         #define V_HUGE 1
  34.     #endif   /* use the HUGE library within the memory model LARGE */
  35.  
  36.     #if defined( V_HUGE )
  37.          #define   V_DATAPTR  huge
  38.          #define   _VFAR      far
  39.          typedef   unsigned long   ui;
  40.     #else
  41.          #if defined __SMALL__ || defined __MEDIUM__
  42.              #define   V_DATAPTR near    /* even in case of DS!=SS  */
  43.              #define   _VFAR     near
  44.          #elif defined __FLAT__
  45.              #define  _VFAR
  46.              #define  V_DATAPTR
  47.          #else
  48.              #define   V_DATAPTR far
  49.              #define   _VFAR     far
  50.          #endif
  51.          typedef   unsigned int    ui;
  52.     #endif
  53.     #if (__BORLANDC__ >= 0x450)
  54.          #define __vf _RTLENTRY _EXPFUNC
  55.     #else
  56.          #define __vf  _Cdecl _FARFUNC
  57.     #endif
  58.     #pragma option -a-  /* avoid insertion of dummy bytes */
  59.     typedef  struct { long Lo, Hi; }  quad;  /* "quadruple int", 64 bit */
  60.     #if !defined( _CMATH_DEFS )
  61.        typedef long double  extended; /* Borland C supports IEEE 80-bit real numbers */
  62.        typedef struct {float    Re, Im;} fComplex;
  63.        typedef struct {double   Re, Im;} dComplex;
  64.        typedef struct {extended Re, Im;} eComplex;
  65.        typedef fComplex fcomplex;
  66.        typedef dComplex dcomplex;
  67.        typedef eComplex ecomplex;  // tolerate all-minuscule
  68.        #define _CMATH_DEFS
  69.     #endif
  70.     #pragma option -a.   /* restore default data packing  */
  71.  
  72. #else  /* the following definitions apply to
  73.           VectorLib for Microsoft's Visual C++ and for
  74.           VectorLib for Powersoft's Optima++ */
  75.     #if !defined(_WIN32)
  76.         #error ERROR: Only Win32 target supported!
  77.     #endif
  78.     #pragma pack(push,1)  /* pack structs without dummy bytes */
  79.     #ifndef _MSC_VER  /* Optima++ */
  80.         #define _WINDOWS
  81.     #endif
  82.     #define __vf  __cdecl
  83.     #define   _VFAR
  84.     #define   V_DATAPTR
  85.     typedef  unsigned int  ui;
  86.     typedef  struct { long Lo, Hi; }  quad;  /* "quadruple int", 64 bit */
  87.     #if !defined( _CMATH_DEFS )
  88.        typedef  double extended; /* Visual C++ and Optima++ do not
  89.                                     support 80-bit IEEE numbers.
  90.                                     So make extended equal to double. */
  91.        typedef struct {float    Re, Im;} fComplex;
  92.        typedef struct {double   Re, Im;} dComplex;
  93.        typedef dComplex                  eComplex;
  94.        #define _CMATH_DEFS
  95.        typedef fComplex fcomplex;
  96.        typedef dComplex dcomplex;
  97.        typedef eComplex ecomplex;  // tolerate all-lower case
  98.     #endif
  99.     #pragma pack(pop)   /* restore default packing */
  100. #endif    /*  Borland C/C++, Visual C++, or Optima++ */
  101.  
  102. typedef   char           V_DATAPTR *    biVector;
  103. typedef   short          V_DATAPTR *    siVector;
  104. typedef   int            V_DATAPTR *    iVector;
  105. typedef   long           V_DATAPTR *    liVector;
  106. typedef   quad           V_DATAPTR *    qiVector;
  107. typedef   unsigned char  V_DATAPTR *    ubVector;
  108. typedef   unsigned short V_DATAPTR *    usVector;
  109. typedef   unsigned int   V_DATAPTR *    uVector;
  110. typedef   unsigned long  V_DATAPTR *    ulVector;
  111. typedef   ui             V_DATAPTR *    uiVector;
  112. typedef   float          V_DATAPTR *    fVector;
  113. typedef   double         V_DATAPTR *    dVector;
  114. typedef   extended       V_DATAPTR *    eVector;
  115. typedef   fComplex       V_DATAPTR *    cfVector;
  116. typedef   dComplex       V_DATAPTR *    cdVector;
  117. typedef   eComplex       V_DATAPTR *    ceVector;
  118. #undef V_DATAPTR
  119.  
  120. #ifdef __cplusplus
  121. extern "C" {
  122. #endif
  123.  
  124. /** Allocation of memory is specific for the respective data type and
  125.     is consequently included in VFstd.h etc.
  126.     Only VBI_vector, VBI_vector0, VUB_vector, and VUB_vector0 are
  127.     included here. They are the only functions for biVectors and
  128.     ubVectors defined so far in VectorLib.                        */
  129.  
  130. biVector __vf VBI_vector( ui size );
  131. biVector __vf VBI_vector0( ui size );
  132. ubVector __vf VUB_vector( ui size );
  133. ubVector __vf VUB_vector0( ui size );
  134.  
  135. /*    Freeing memory is the same for all data types: */
  136. void  __vf  V_free( void _VFAR *X );
  137. void  __vf  V_freeAll( void );  /* frees all vectors allocated by V.._vector */
  138. void  __vf  V_nfree( unsigned numfree,...); /* e.g., V_nfree( 2, X, Y ); */
  139.  
  140.  
  141. /********  user-accessible error handling functions ***************/
  142.  
  143. void  __vf  V_noteError( char _VFAR *fname, unsigned why );
  144. void  __vf  V_printErrorMsg( char _VFAR *ErrMsg );
  145. void  __vf  V_setErrorEventFile( char _VFAR *filename,  unsigned ScreenAndFile );
  146. void  __vf  V_closeErrorEventFile( void );
  147.  
  148.  
  149. #if defined __BORLANDC__
  150.     /*** translation of calls to matherr() into _matherr() for BorlandC 4.0+ ***/
  151.     #if (__BORLANDC__ >= 0x450) && !defined (__FLAT__)
  152.         #if !defined( __MATH_H )
  153.             #include <math.h>
  154.         #endif
  155.         int  _Cdecl _FARFUNC matherr (struct exception _VFAR *__e);
  156.         #define NEWMATHERR  \
  157.             int matherr( struct exception _VFAR *__e ) \
  158.             {  return( _matherr( __e )); }
  159.     #else   /* either FLAT model or older versions of Borland C++ */
  160.         #define NEWMATHERR
  161.     #endif
  162. #else  /* for Visual C++ and Optima++  */
  163.     #define NEWMATHERR
  164. #endif
  165.  
  166.  
  167. /************ Integer OVERFLOW handling **************************/
  168.  
  169. #ifdef V_trapIntError
  170.    typedef enum
  171.    {
  172.          ierrIgnore = 0,
  173.          ierrNote,
  174.          ierrAbort
  175.    }   V_ihand;
  176.  
  177.    void __vf  V_setIntErrorHandling( V_ihand a );
  178. #endif
  179.  
  180.         /*  constructors of complex data types:   */
  181. fComplex __vf fcplx( float    __ReVal, float    __ImVal);
  182. dComplex __vf dcplx( double   __ReVal, double   __ImVal);
  183. #ifdef __BORLANDC__
  184.    eComplex __vf ecplx( extended __ReVal, extended __ImVal);
  185. #else  /* Visual C++, Optima++ */
  186.    #define ecplx dcplx
  187. #endif
  188.      /*  for overloaded constructors and for all "non-vector"
  189.          operations on complex numbers, see CMATH with the
  190.          include-files <newcplx.h> and <cmath.h> !          */
  191. #ifdef __cplusplus
  192. }  // end of 'extern "C" '
  193. #endif
  194.  
  195.  
  196. #endif  /*  __VECLIB_H  */
  197.